package algorithm.easy;

/**
 * @author 江岸
 * @version V1.0
 * @ClassName: longestCommonPrefix14
 * @description: 编写一个函数来查找字符串数组中的最长公共前缀。
 * @date 2020/8/2414:43
 * @since V1.0
 */
public class longestCommonPrefix14 {

    public static void main(String[] args) {
        String[] strs = {""};
        String s = longestCommonPrefix(strs);
        System.out.println(s);
    }

    public static String longestCommonPrefix(String[] strs) {
        if(strs.length == 0)
            return "";
        String ans = strs[0];
        for(int i =1;i<strs.length;i++) {
            int j=0;
            for(;j<ans.length() && j < strs[i].length();j++) {
                if(ans.charAt(j) != strs[i].charAt(j))
                    break;
            }
            ans = ans.substring(0, j);
            if(ans.equals(""))
                return ans;
        }
        return ans;

    }
}
